package com.spider.demo6tcp3;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ServerReader extends Thread{
    private Socket socket;
    public ServerReader(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //负责读取管道的消息
            try {
                InputStream is = socket.getInputStream();
                DataInputStream dis = new DataInputStream(is);
                while ( true){
                    String msg = dis.readUTF();
                    System.out.println("服务端收到消息："+msg);
                    System.out.println("客户端的IP="+socket.getInetAddress().getHostAddress());
                    System.out.println("客户端的端口="+socket.getPort());
                    System.out.println("-------------------------------------------------------------");
                }

            } catch (IOException e) {
                System.out.println("客户端"+ socket.getInetAddress().getHostAddress()+"已退出");
            }

    }
}
